fix(writers/python): prevent code injection via x-ms-enum description#7735
Merged
Conversation
… newlines The RemoveInvalidDescriptionCharacters method in PythonConventionService did not strip newline characters (\r\n, \r, \n). A malicious OpenAPI spec could inject arbitrary Python code via x-ms-enum description fields by embedding newlines that break out of inline comments (# ...) or docstrings. This fix replaces newlines with spaces, keeping all description content on a single line where it remains safely within comments/docstrings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… newlines The RemoveInvalidDescriptionCharacters method in PythonConventionService did not strip newline characters (\r\n, \r, \n). A malicious OpenAPI spec could inject arbitrary Python code via x-ms-enum description fields by embedding newlines that break out of inline comments (# ...) or docstrings. This fix replaces newlines with spaces, keeping all description content on a single line where it remains safely within comments/docstrings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
baywet
previously approved these changes
May 26, 2026
Member
|
@MIchaelMainer some unit tests are failing. Could be transient. |
…b.com/microsoft/kiota into fix/python-enum-description-injection
baywet
reviewed
May 27, 2026
…nitization The Python writer now normalizes description control characters (newline, carriage return, tab) to spaces as part of injection hardening. This caused EscapesDeprecationWarningStringLiteral to expect an outdated \n sequence in the generated warning output.
…itory-wide defaults
…ty in StreamJsonRpc
Code Coverage OverviewLanguages: C# C# / code-coverage/dotnetThe overall coverage in the branch is 71%. Coverage data for the branch is not yet available. Show a code coverage summary of the most covered files.
Code Coverage is in Public Preview. Learn more and provide us with your feedback. |
Member
|
currently impacted by this microsoft/vs-streamjsonrpc#1447 |
baywet
approved these changes
Jun 2, 2026
This was referenced Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a code injection vulnerability in the Python writer where malicious x-ms-enum description fields containing newline characters could break out of
inline comments (# ...) or docstrings and inject arbitrary Python code into generated output.
Changes
triple-quote replacements.
Root Cause
The RemoveInvalidDescriptionCharacters method only handled backslash and triple-quote escaping but did not strip newline characters. Since Python
inline comments are single-line (# ...), an embedded newline would terminate the comment and allow subsequent text to execute as Python code.
Security Impact
A malicious OpenAPI specification could inject arbitrary Python code into generated SDK clients via the x-ms-enum extension's description field.